package com.taijihuabao.modules.controller;

import com.taijihuabao.common.jsonresult.JsonResult;
import com.taijihuabao.common.redisconfig.UserLoad;
import com.taijihuabao.modules.entity.ExpenseEntity;
import com.taijihuabao.modules.service.ExpenseFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @title: ApprovallController
 * @Author luoxianan
 * @Date: 2021/12/9 14:05
 * @Version 1.0
 */
@Api(tags = "报销管理")
@RestController
@RequestMapping("/api/v1/expense")
public class ExpenseController {
    @Autowired
    private ExpenseFlowService expenseFlowService;


    @ApiOperation("部署流程")
    @GetMapping("/deloy")
    public JsonResult deloy(){
        expenseFlowService.saveNewDeploye();
        return JsonResult.success();
    }

    @ApiOperation("发起申请")
    @GetMapping("/initApply")
    public JsonResult initApply(@RequestBody ExpenseEntity expenseEntity){
        expenseFlowService.initApply(expenseEntity);
        return JsonResult.success();
    }

    @ApiOperation("根据报销单号查询审批单")
    @PostMapping("/selectByExpenseId")
    public JsonResult selectByExpenseId(@RequestBody ExpenseEntity expenseEntity){
        ExpenseEntity expenseEntity1 = expenseFlowService.selectByExpenseId(expenseEntity);
        return JsonResult.success(expenseEntity1);
    }

    @ApiOperation("查询待办")
    @PostMapping("/selectTask")
    public JsonResult selectByExpenseUserId(){
        Long id = UserLoad.getUser().getId();
        List<ExpenseEntity> list = expenseFlowService.selectByExpense(id);
        return JsonResult.success(list);
    }

    @ApiOperation("根据申请人id查询审批单")
    @PostMapping("/selectByApplyUserId")
    public JsonResult selectByApplyUserId(@RequestBody ExpenseEntity expenseEntity){
        List<ExpenseEntity> expenseEntities = expenseFlowService.selectByApplyUserId(expenseEntity);
        return JsonResult.success(expenseEntities);
    }

//    @ApiOperation("查询报销流程过程")
//    @PostMapping("/historyActInstanceList")
//    public JsonResult historyActInstanceList(@RequestBody ExpenseEntity expenseEntity){
//        List<ActivitiVO> activitiVOList = expenseFlowService.historyActInstanceList(expenseEntity);
//        return JsonResult.success(activitiVOList);
//    }

    @ApiOperation("完成审批")
    @PostMapping("/expenseTask")
    public JsonResult expenseTask(@RequestBody ExpenseEntity expenseEntity){
        Long id = UserLoad.getUser().getId();
        expenseFlowService.expenseTask(id,expenseEntity);
        return JsonResult.success();
    }
    @ApiOperation("查询已办")
    @PostMapping("/completeTask")
    public JsonResult completeTask(){
        Long id = UserLoad.getUser().getId();
        List<ExpenseEntity> entityList = expenseFlowService.completeTask(id);
        return JsonResult.success(entityList);
    }
}
